home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / Archive / XPK / xpk_Source / examples / XpkSAS.c < prev    next >
C/C++ Source or Header  |  1998-11-15  |  2KB  |  79 lines

  1. /* XPK - General XPK file-to-file packer/unpacker */
  2. /* This is the version to be compiled with SAS/C  */
  3.  
  4. #include <proto/exec.h>
  5. #include <proto/dos.h>
  6. #include <proto/xpkmaster.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. struct Library *XpkBase;
  12. char errbuf[XPKERRMSGSIZE + 1];    /* +1 to make room for '\n'        */
  13.  
  14. /* disable lattice CTRL-C handling */
  15. int chkabort (void)
  16. {
  17.   return 0;
  18. }
  19.  
  20. long __asm __saveds chunkfunc(register __a1 struct XpkProgress *prog)
  21. {
  22.   long i;
  23.  
  24.   printf("\r%4s: %-9s %-12s (%6d bytes, %3d%% done, %2d%% CF, %6d cps) ",
  25.     prog->xp_PackerName, prog->xp_Activity, prog->xp_FileName,
  26.     prog->xp_ULen, prog->xp_Done, prog->xp_CF, prog->xp_Speed);
  27.   if(prog->xp_Type == XPKPROG_END || (i = (long)
  28.   SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C))
  29.     printf("\n");
  30.  
  31.   return i;
  32. }
  33. struct Hook chunkhook =
  34. { {0}, chunkfunc};
  35.  
  36. struct TagItem tags[]=
  37. {
  38.   XPK_InName, (long) NULL,
  39.   XPK_OutName, (long) NULL,
  40.   XPK_Ignore, (long) 0,
  41.   XPK_NoClobber, (long) TRUE,
  42.   XPK_GetError, (long) errbuf,
  43.   XPK_ChunkHook, (long) &chunkhook,
  44.   TAG_DONE};
  45.  
  46. void end (char *text)
  47. {
  48.   if (text)
  49.     Write (Output (), text, strlen (text));
  50.   if (XpkBase)
  51.     CloseLibrary (XpkBase);
  52.   exit (text ? 10 : 0);
  53. }
  54.  
  55. void main (int argc, char *argv[])
  56. {
  57.   int res;
  58.  
  59.   if (!(XpkBase = OpenLibrary (XPKNAME, 0)))
  60.     end ("Cannot open " XPKNAME "\n");
  61.  
  62.   if ((argc < 3) || (argc > 4))
  63.     end ("Usage: XPK [<method>] <infile> <outfile>\n");
  64.  
  65.   tags[0].ti_Data = (long) argv[argc - 2];    /* First try to decompress... */
  66.   tags[1].ti_Data = (long) argv[argc - 1];
  67.   if (argc == 3)
  68.     res = XpkUnpack (tags);
  69.   else {
  70.     tags[2].ti_Tag = XPK_PackMethod;
  71.     tags[2].ti_Data = (long) argv[1];
  72.     res = XpkPack (tags);
  73.   }
  74.   if (res)
  75.     end (strcat (errbuf, "\n"));
  76.  
  77.   end (NULL);
  78. }
  79.